<template>
    <view class="page-wrapper">
        <view class="menu-list"  style="margin-top: 60rpx;">
			<view class="menu-item" >
				<view class="label-box">
					<text>{{ $t('pages.account.MobileNumber') }}</text>
				</view>
				<view class="label-box">
                    <text>
					    {{ formData.mobile }}
                    </text>
				</view>
			</view>
			<view class="menu-item">
				<view class="label-box">
					<text>{{ $t('pages.account.Email') }}</text>
				</view>
				<view class="label-box">
                    <text>{{ formData.email }}</text>
				</view>
			</view>
            <view class="menu-item" @click="navigateToUniPage('/pages/setting/resetPwd')">
				<view class="label-box">
					<text>{{ $t('pages.account.ChangeLoginPassword') }}</text>
				</view>
				<view class="label-box">
					<up-icon name="arrow-right" class="icon"></up-icon>
				</view>
			</view>
		</view>

        <view class="bottom-box">
            <up-button @click.stop="deleteAccount" :text="$t('pages.account.DeleteAccountBtn')" size="normal" type="error" style="width: 600rpx;" shape="circle"></up-button>
        </view>
    </view>
</template>

<script setup>
import { CacheUtils, navigateToUniPage, } from '@/utils/index';
import { reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { zhuxiaoAPiu } from "@/api/request.js";
import { useI18n } from 'vue-i18n';
import { Regexp_Utils } from '@/utils/validate.js';
	
const { t } = useI18n();
const formData = reactive({
    mobile: '',
    email: '',
});

const deleteAccount = ()=>{
    uni.showModal({
        title: t('pages.account.DeleteConfirmTitle'),
        content: t('pages.account.DeleteConfirmDesc'),
        confirmText: t('common.confirm'),
		cancelText:  t('common.cancel'),
        success: async function (res) {
            if (res.confirm) {
                let data = await zhuxiaoAPiu()
                if (data.response.result == true) {
                    CacheUtils.remove('userid');
                    CacheUtils.remove('userInfo');
                    navigateToUniPage('/pages/login/index');
                } else {
                    uni.showToast({
                        title: data.response.msg,
                        icon: 'none'
                    });
                } 
            }        
        }
    });
}

onLoad(()=>{
   const data =  CacheUtils.get('userInfo');
   	if(Regexp_Utils.mail.test(data.tel)){
   		formData.email = data.tel;		
   	}else{
   		formData.mobile = data.tel;				
   	}
})
</script>

<style lang="scss" scoped>
.menu-item{
    font-weight: normal;
}   

.page-wrapper{
    position: relative;
    .bottom-box{
        bottom: 30rpx;
        left: 20rpx;
        right: 20rpx;
        position: fixed;
        display: flex;
        justify-content: center;
    }
}
</style>